<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript">
	$(function() {
		
		parent.$.messager.progress('close');
		CommUtil.Area.regetst({province :'srcProvinceId' , city:'srcCityId' , district:'srcAreaId',districtId:'${shOrders.srcAreaId}'});
		CommUtil.Area.regetst({province :'desProvinceId' , city:'desCityId' , district:'desAreaId',districtId:'${shOrders.desAreaId}'});
		
		var paymentStatus = '${shOrders.paymentStatus}';
		
		var comboboxExpress = $.parseJSON(sessionStorage.getItem("comboboxExpress"));
		$('#company_id').combobox({
			data:comboboxExpress,
			panelHeight:'auto',
			editable:false,
			onChange: function(newValue,oldValue){
				getTotalFee();
			}
		}); 
		
		
		$('#status').combobox({
			data : [{"value":1,"text":"待处理"},
			        {"value":2,"text":"已发件"},
			        {"value":3,"text":"关闭"},
			        {"value":4,"text":"删除"},
			        {"value":5,"text":"已取件"}],
		    panelHeight:'auto',
		    value : '${shOrders.status}'
		});
		
		
		var amount = '${shOrders.amount}';
		
		if(amount != '') {
			$('#showAmount').val(amount/100);
		}
		
		var weight = '${shOrders.weight}';
		
		if(weight != '') {
			$('#showWeight').val(weight/1000);
		}
		
		$('#form').form({
			url : '/sendCourierController/edit',
			onSubmit : function() {
				
				if($('#showWeight').val() != null) {
					$('#weight').val($('#showWeight').val()*1000);
				}
				if($('#showAmount').val() != null) {
					$('#amount').val($('#showAmount').val()*100);
				}
				parent.$.messager.progress({
					title : '提示',
					text : '数据处理中，请稍后....'
				});
				var isValid = $(this).form('validate');
				if (!isValid) {
					parent.$.messager.progress('close');
				}
				return isValid;
			},
			success : function(result) {
				parent.$.messager.progress('close');
				result = $.parseJSON(result);
				parent.$.messager.alert("提示",result.msg, 'info');
				if (result.success) {
					parent.$.modalDialog.openner_dataGrid.datagrid('reload');
					parent.$.modalDialog.handler.dialog('close');
				}
			}
		});
		
		$('#srcMobile').change(function(){
			  var mobile = $(this).val();
			  if($(this).validatebox('isValid')) {
				  $.ajax({
						type:'post',
						url:'/sendCourierController/getSrcAccountInfo',
						data:{'mobile':mobile},
						success:function(result) {
							if(result != null) {
								if(result.id != null) {
									$('#srcAccountId').val(result.id);
								}
								if(result.name != null && result.name != "") {
									$('#srcAccountName').val(result.name);
								}
							}
						},
						dataType:'json'
					});
			  }
		});
		
		$('#desMobile').change(function(){
			  var accountId = $("#srcAccountId").val();
			  var mobile = $(this).val();
			  if($(this).validatebox('isValid')) {
				  $.ajax({
						type:'post',
						url:'/sendCourierController/getHistoryAccountInfo',
						data:{'accountId':accountId,'mobile':mobile},
						success:function(result) {
							if(result != null) {
								if(result.id != null) {
									$('#desAccountId').val(result.id);
								}
								if(result.areaDetail != null && result.areaDetail != "") {
									$('#desAreaDetail').val(result.areaDetail);
								}
								if(result.name != null && result.name != "") {
									$('#desAccountName').val(result.name);
								}
								if(result.areaId != null) {
									CommUtil.Area.regetst({province :'desProvinceId' , city:'desCityId' , district:'desAreaId',districtId:result.areaId});
								}
							}
						},
						dataType:'json'
					});
			  }
		});
		
	  	
	  	
		$('#desProvinceId').combobox({
			onChange: function(newValue,oldValue){
				getTotalFee();
			}
		});
		
		if(paymentStatus != 1) {
			$('#company_id').combobox('readonly');
			$('#desProvinceId').combobox('readonly');
		}
		
		$('#showWeight').numberbox({
			onChange: function(newValue,oldValue){
				getTotalFee();
			}
		});
	});
	
	function getTotalFee() {
		var companyId = $("#company_id").combobox('getValue');
		var weight = $("#showWeight").val()*1000;
		var desProvinceId = $("#desProvinceId").combobox('getValue');
		$("#showAmount").numberbox('setValue', 0);
		if(companyId == null || companyId == "") {
			return false;
		}
		if(desProvinceId == null || desProvinceId == "") {
			return false;
		}	
		$.ajax({
			type:'post',
			url:'/sendCourierController/getTotalFee',
			data:{'companyId':companyId,'weight':weight,'desProvinceId':desProvinceId},
			success:function(result) {
				if(result != null && result != "") {
					var amount = result/100;
					$("#showAmount").numberbox('setValue', amount);
					return true;
				}else {
					return false;
				}
			},
			dataType:'text'
		}); 
	}
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'center',border:false" title="" style="overflow: hidden;">
		<form id="form" method="post">
			<input name="id" type="hidden" value="${shOrders.id}" />
			<input name="srcAccountId" id="srcAccountId" type="hidden" value="${shOrders.srcAccountId}" />
			<input name="desAccountId" id="desAccountId" type="hidden" value="${shOrders.desAccountId}" />
			<table class="table table-hover table-condensed">
				<tr>
					<td colspan="4" style="font-weight: bold;">快递信息</td>
				</tr>
				<tr>
					<td>快递点</td>
					<td >
						<input name="companyId" id="company_id" value="${shOrders.companyId}" style="width: 180px" />
					</td>
					<td>快递单号</td>
					<td >
						<input name="outBizNum" type="text" style="width: 180px"  value="${shOrders.outBizNum}" />
					</td>
				</tr>
				<tr>
					<td>订单名称</td>
					<td >
						<input name="name" type="text" style="width: 180px" value="${shOrders.name}" class="easyui-validatebox" required="required"/>
					</td>
					<td>快递重量（千克）</td>
					<td >
						<input id="showWeight" type="text" style="width: 180px" class="easyui-numberbox" precision="3" min="0" max="9999.999" value="0" ${(shOrders.paymentStatus!='1')?'readonly' : ''} />
						<input name="weight" id="weight" type="hidden" />
					</td>
				</tr>
				<tr>
					<td colspan="4" style="font-weight: bold;">发件人信息</td>
				</tr>
				<tr>
					<td>发件人手机号</td>
					<td >
						<input id="srcMobile" name="srcMobile" type="text" style="width: 180px" class="easyui-validatebox" data-options="validType:'isPhoneNumber'" required="required" value="${shOrders.srcMobile}"/>
					</td>
					<td>发件人名称</td>
					<td >
						<input name="srcAccountName" id="srcAccountName" type="text" style="width: 180px" class="easyui-validatebox" required="required" value="${shOrders.srcAccountName}"/>
					</td>
				</tr>
				<tr>
					<td>发件地区</td>
					<td colspan="3">
						<input id="srcProvinceId" style="width: 148px">
						<input id="srcCityId" style="width: 148px">
						<input name="srcAreaId"  id="srcAreaId" style="width: 148px">
					</td>
				</tr>
				<tr>
					<td>发件街道门牌地址</td>
					<td >
						<input name="srcAreaDetail" id="srcAreaDetail" type="text" style="width: 180px" class="easyui-validatebox" required="required"  value="${shOrders.srcAreaDetail}"/>
					</td>
					<td>发件人身份证号</td>
					<td >
						<input name="srcCertId" id="srcCertId" type="text" style="width: 180px"  value="${shOrders.srcCertId}"/>
					</td>
				</tr>
				<tr>
					<td colspan="4" style="font-weight: bold;">收件人信息</td>
				</tr>
				<tr>
					<td>收件人手机号</td>
					<td >
						<input id="desMobile" name="desMobile" type="text" style="width: 180px" class="easyui-validatebox" data-options="validType:'isPhoneNumber'" required="required" value="${shOrders.desMobile}"/>
					</td>
					<td>收件人名称</td>
					<td >
						<input name="desAccountName" id="desAccountName" type="text" style="width: 180px" class="easyui-validatebox" required="required" value="${shOrders.desAccountName}"/>
					</td>
				</tr>
				<tr>
					<td>收件地区</td>
					<td colspan="3">
						<input id="desProvinceId" style="width: 148px">
						<input id="desCityId" style="width: 148px">
						<input name="desAreaId"  id="desAreaId" style="width: 148px">
					</td>
				</tr>
				<tr>
					<td>收件街道门牌地址</td>
					<td>
						<input name="desAreaDetail" id="desAreaDetail" type="text" style="width: 180px" class="easyui-validatebox" required="required" value="${shOrders.desAreaDetail}"/>
					</td>
					<td>快递状态</td>
					<td >
						<input name="status" id="status" type="text" style="width: 180px"  />
					</td>
				</tr>
				<tr>
					<td>快递金额（元）</td>
					<td>
						<input id="showAmount" type="text" style="width: 180px" class="easyui-numberbox" precision="2" min="0" max="99999.99" value="0" readonly="readonly"/>
						<input name="amount" id="amount" type="hidden" />
					</td>
					<td>支付状态</td>
					<td >
						<c:if test="${shOrders.paymentStatus=='1'}">
							<input name="paymentStatus" type="radio" value="1" checked/>未支付
							<input name="paymentStatus" type="radio" value="2" />已现金支付
						</c:if>
						<c:if test="${shOrders.paymentStatus=='2'}">
							已现金支付
						</c:if>
						<c:if test="${shOrders.paymentStatus=='3'}">
							已线上支付
						</c:if>
					</td>
				</tr>
				<tr>
					<td>备注</td>
					<td colspan="3">
						<textarea name="remark" rows="3" cols="10" style="width: 461px;height: 80px">${shOrders.remark}</textarea>
					</td>
				</tr>
			</table>
		</form>
	</div>
</div>